package com.shangyueshang.controller.finance;

import com.shangyueshang.model.FixedCost;
import com.shangyueshang.request.FixedCostDTO;
import com.shangyueshang.request.PageReq;
import com.shangyueshang.response.HttpResult;
import com.shangyueshang.response.PageResult;
import com.shangyueshang.service.FixedCostService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: JokeyZheng
 * @email: zhengjingfeng@ruqimobility.com
 * @created: 2022/1/17 17:05
 * @version: v1.0.0
 */
@RestController
@RequestMapping("/fixed")
public class FixedCostController {
	
	@Resource
	private FixedCostService fixedCostService;
	
	/**
	 * 分页查询
	 *
	 * @param pageReq
	 * @return
	 */
	@PostMapping("/findPage")
	@PreAuthorize("hasAuthority('finance:fixed:view')")
	public HttpResult<PageResult<FixedCost>> findPage(@RequestBody PageReq pageReq) {
		return HttpResult.ok(fixedCostService.findPage(pageReq));
	}
	
	/**
	 * 保存固定成本
	 *
	 * @param fixedCost
	 * @return
	 */
	@PostMapping("/save")
	@PreAuthorize("hasAnyAuthority('finance:fixed:add','finance:fixed:edit')")
	public HttpResult<Void> save(@RequestBody FixedCostDTO fixedCost) {
		return fixedCostService.saveUpdate(fixedCost);
	}
}
